using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DSEngine.Stage;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace DSEngine.Sprite
{
    public class SpText : SpExtendObject
    {
        SpriteFont font;
        public Layout Parent { get; set; }
        public Color Color { get; set; }
        public float FontSize { get; set; }
        public Vector2 Center
        {
            get
            {
                Vector2 v = this.Position;
                Vector2 size = font.MeasureString(Text);
                return (v + size / 2);
            }
            set 
            {
                Vector2 v = value;
                Vector2 size = font.MeasureString(Text);
                this.Position = (v - size / 2);
            }

        }
        public SpText(Layout layout,string fontAssitName)
        {
            Parent = layout;
            font = layout.Content.Load<SpriteFont>(fontAssitName);
            this.Color = Color.White;
            this.Text = "";
        }
        public string Text { get; set; }
        protected override void InnerUpdate(Microsoft.Xna.Framework.GameTime gt)
        {
            base.InnerUpdate(gt);
        }
        public override float Width
        {
            get
            {
                return font.MeasureString(Text).X;
            }
            set
            {
                base.Width = value;
            }
        }
        public override float Height
        {
            get
            {
                return font.MeasureString(Text).Y;
            }
            set
            {
                base.Height = value;
            }
        }
        protected override List<BoundingBox> UpdateBoundingBox(GameTime gameTime)
        {
            return base.UpdateBoundingBox(gameTime);
        }
        protected override void InnerDraw(Microsoft.Xna.Framework.GameTime gt)
        {
            base.InnerDraw(gt);
            Vector2 size = font.MeasureString(Text);
            this.Width = size.X;
            this.Height = size.Y;
            this.Parent.SpriteBatch.DrawString(
                font, 
                this.Text,
                this.Position + size / 2, 
                this.Color,
                this.Rotation,
                size/2,
                this.Scale,
                SpriteEffects.None,0);
        }
    }
}
